13 while (cin
>> n
&& n
){
15 cin
>> start
, --start
;
19 while (cin
>> p
>> q
&& (p
+q
)){
23 for (int i
=0; i
<n
; ++i
){
24 sort(g
[i
].begin(), g
[i
].end());
27 int answer
= -1, length
= -1;
31 for (int i
=0; i
<n
; ++i
) d
[i
] = INT_MIN
;
38 if (d
[u
] > length
|| (d
[u
] == length
&& u
< answer
)){
42 vector
<int> &vecinos
= g
[u
];
43 for (int i
=0; i
<vecinos
.size(); ++i
){
45 if (d
[u
] + 1 > d
[v
]){ //Puedo llegar en un camino más largo
51 cout
<< "Case " << C
++ << ": The longest path from " << start
+ 1 << " has length ";
52 cout
<< length
<< ", finishing at " << answer
+ 1 << "." << endl
<< endl
;